load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@rules_apple//apple:macos.bzl", "macos_command_line_application")
load(
    "@rules_xcodeproj//xcodeproj:defs.bzl",
    "top_level_target",
    "xcodeproj",
)
load(
    "bazel/files.bzl",
    "MLN_MACOS_PRIVATE_HEADERS",
    "MLN_MACOS_PUBLIC_HEADERS",
    "MLN_MACOS_PUBLIC_METAL_HEADERS",
    "MLN_MACOS_PUBLIC_OBJCPP_METAL_SOURCE",
    "MLN_MACOS_PUBLIC_OBJCPP_SOURCE",
    "MLN_MACOS_PUBLIC_OBJC_SOURCE",
)

filegroup(
    name = "macos_private_hdrs",
    srcs = MLN_MACOS_PRIVATE_HEADERS,
    visibility = ["//visibility:public"],
)

filegroup(
    name = "macos_public_hdrs",
    srcs = MLN_MACOS_PUBLIC_HEADERS + MLN_MACOS_PUBLIC_METAL_HEADERS,
    visibility = ["//visibility:public"],
)

filegroup(
    name = "macos_objcpp_srcs",
    srcs = MLN_MACOS_PUBLIC_OBJCPP_SOURCE + MLN_MACOS_PUBLIC_OBJCPP_METAL_SOURCE,
    visibility = ["//visibility:public"],
)

filegroup(
    name = "macos_objc_srcs",
    srcs = MLN_MACOS_PUBLIC_OBJC_SOURCE,
    visibility = ["//visibility:public"],
)

macos_command_line_application(
    name = "MapLibreMac",
    minimum_deployment_os_version = "13.0",
    minimum_os_version = "13.0",
    visibility = ["//visibility:public"],
    deps = ["//platform:macos-objcpp"],
)

xcodeproj(
    name = "xcodeproj",
    bazel_env = {"PATH": "/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin"},
    default_xcode_configuration = "Debug",
    minimum_xcode_version = "14",
    project_name = "MapLibre",
    tags = ["manual"],
    top_level_targets = [
        top_level_target(
            "//platform/macos:MapLibreMac",
            target_environments = [
                "simulator",
            ],
        ),
        top_level_target(
            "//platform/macos/app:macos_app",
        ),
        top_level_target(
            "//platform/glfw:glfw_app",
        ),
    ],
    xcode_configurations = {
        "Debug": {"//command_line_option:compilation_mode": "dbg"},
        "Release": {"//command_line_option:compilation_mode": "opt"},
    },
)

exports_files(
    MLN_MACOS_PRIVATE_HEADERS +
    MLN_MACOS_PUBLIC_HEADERS +
    MLN_MACOS_PUBLIC_OBJCPP_SOURCE +
    MLN_MACOS_PUBLIC_OBJCPP_METAL_SOURCE +
    MLN_MACOS_PUBLIC_OBJC_SOURCE,
)

js_library(
    name = "symbols-to-check",
    srcs = [
        ":macos_objc_srcs",
        ":macos_objcpp_srcs",
        ":macos_private_hdrs",
        ":macos_public_hdrs",
    ],
    visibility = ["//platform:__pkg__"],
)
